package sysint.json.sysint;


import java.util.Properties;

import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class SendMail {

	private String intAirportRef;


	public SendMail(String intAirportRef)
	{
		this.intAirportRef = intAirportRef;
	}
	
	
	public void sendMail() throws Exception
	{
		//removed info 4 checkin
		Properties props = System.getProperties();
		props.put("mail.smtp.host", "SMTPHOST");
		props.put("mail.smtp.port", "25");
		props.put("mail.transport.protocol","smtp");
		props.put("mail.smtp.auth", "true");
		props.put("mail.smtp.starttls.enable", "true");
		props.put("mail.smtp.tls", "true");
		props.put("mail.smtp.user", "EXAMPLENAME@PROVIDER.COM");
		props.put("mail.password", "PASSWORD");
		 
		javax.mail.Authenticator auth = new javax.mail.Authenticator() {
		   @Override
		   public PasswordAuthentication getPasswordAuthentication() {
		      return new PasswordAuthentication("EXAMPLENAME@PROVIDER.COM","PASSWORD");
		   }
		};
		 
		Session session = Session.getDefaultInstance(props, auth);
		 
		Message msg = new MimeMessage(session);
		msg.setFrom(new InternetAddress("EXAMPLENAME@PROVIDER.COM", "EXAMPLENAME"));
		msg.addRecipient(Message.RecipientType.TO, new InternetAddress("TOEXAMPLE@EXAMPLEPROVIDER.COM", "TOEXAMPLE"));
		msg.setSubject("SUBJECT");
		msg.setText("Some Problem within the flight occured! \n" + intAirportRef);
		msg.saveChanges();
		Transport.send(msg);
	}
	
}
